package com.springcloud.controller;

import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName : MyErrorController
 * @Author : 司猫子
 * @Date: 2021/4/13 2:23
 */
@RestController
public class MyErrorController implements ErrorController {
    @Override
    public String getErrorPath() {
        return "/error";
    }
    @RequestMapping("/error")
    public Object error(){
        ZuulException exception = (ZuulException) RequestContext.getCurrentContext().getThrowable();
        return "全局错误页面<br>异常类型:"+exception.getClass()+"异常信息:"+exception.getMessage();
    }
}
